package com.springdoor.goods.service.impl;

import java.util.List;
import com.springdoor.common.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.springdoor.goods.mapper.SprdCommonImagesMapper;
import com.springdoor.goods.domain.SprdCommonImages;
import com.springdoor.goods.service.ISprdCommonImagesService;

/**
 * 图片资源Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-14
 */
@Service
public class SprdCommonImagesServiceImpl implements ISprdCommonImagesService 
{
    @Autowired
    private SprdCommonImagesMapper commonImagesMapper;

    /**
     * 查询图片资源
     * 
     * @param imageId 图片资源主键
     * @return 图片资源
     */
    @Override
    public SprdCommonImages selectSprdCommonImagesByImageId(Long imageId)
    {
        return commonImagesMapper.selectSprdCommonImagesByImageId(imageId);
    }

    /**
     * 查询图片资源列表
     * 
     * @param SprdCommonImages 图片资源
     * @return 图片资源
     */
    @Override
    public List<SprdCommonImages> selectSprdCommonImagesList(SprdCommonImages SprdCommonImages)
    {
        return commonImagesMapper.selectSprdCommonImagesList(SprdCommonImages);
    }

    /**
     * 新增图片资源
     * 
     * @param commonImages 图片资源
     * @return 结果
     */
    @Override
    public int insertSprdCommonImages(SprdCommonImages commonImages)
    {
        int row = 0;
        Integer orderNum = commonImages.getOrderNum();
        if (orderNum == null || orderNum <= 0) {
            orderNum = commonImagesMapper.findMaxOrderNum(commonImages.getgNumber());
        }
        if (StringUtils.isNotEmpty(commonImages.getImagePath())) {
            String[] split = commonImages.getImagePath().split(",");
            for (String path : split) {
                if (StringUtils.isNotBlank(path)) {
                    commonImages.setImagePath(path);
                    commonImages.setOrderNum(orderNum++);
                    row += commonImagesMapper.insertSprdCommonImages(commonImages);
                }
            }
        }
        return row;
    }

    /**
     * 修改图片资源
     * 
     * @param SprdCommonImages 图片资源
     * @return 结果
     */
    @Override
    public int updateSprdCommonImages(SprdCommonImages SprdCommonImages)
    {
        return commonImagesMapper.updateSprdCommonImages(SprdCommonImages);
    }

    /**
     * 批量删除图片资源
     * 
     * @param imageIds 需要删除的图片资源主键
     * @return 结果
     */
    @Override
    public int deleteSprdCommonImagesByImageIds(Long[] imageIds)
    {
        return commonImagesMapper.deleteSprdCommonImagesByImageIds(imageIds);
    }

    /**
     * 删除图片资源信息
     * 
     * @param imageId 图片资源主键
     * @return 结果
     */
    @Override
    public int deleteSprdCommonImagesByImageId(Long imageId)
    {
        return commonImagesMapper.deleteSprdCommonImagesByImageId(imageId);
    }

    @Override
    public List<SprdCommonImages> findNoSelImagesList(SprdCommonImages sprdCommmonImages) {
        return commonImagesMapper.findNoSelImagesList(sprdCommmonImages);
    }
}
